/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.factory;

import ru.rakev.matcher.factory.ProducerMatcherAdapterFactory;
import ru.rakev.matcher.ProducerMatcherAdapter;
import ru.rakev.producer.Producer;
import ru.jSkyRoom.interfaces.major.Enchantment;
import ru.jSkyRoom.interfaces.major.Major;
import ru.jSkyRoom.interfaces.additional.HasEnchantment;
import ru.rakev.matcher.Matcher;
import ru.rakev.matcher.factory.MatcherFactory;

/**
 *
 * @author Rakev
 */
public class MajorMatcherFactory {

    private static MajorMatcherFactory instance = new MajorMatcherFactory();
    private MajorProducerFactory producerFactory = MajorProducerFactory.create();

    public static MajorMatcherFactory create() {
        return instance;
    }

    protected MajorMatcherFactory() {
    }

    public <T extends Major> Matcher<T> create(String regexEdid) {
        Matcher<String> regexMatcher = getMatcherFactory().regex(regexEdid);
        Producer<T, String> edidProducer = producerFactory.createEdidProducer();
        return ProducerMatcherAdapterFactory.create().create(edidProducer, regexMatcher);
    }

    public <T extends HasEnchantment> Matcher<T> create(Matcher<Enchantment> enchantmentMatcher) {
        Producer<T, Enchantment> edidProducer = producerFactory.createEnchantmentProducer();
        return new ProducerMatcherAdapter<>(edidProducer, enchantmentMatcher, false);
    }

    protected MatcherFactory getMatcherFactory() {
        return MatcherFactory.create();
    }
}
